package com.zhixi.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @ClassName MyMetaObjectHandler
 * @Author zhangzhixi
 * @Description MP公共字段自动填充
 * @Date 2022-7-10 10:42
 * @Version 1.0
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段自动填充【insert】");
        metaObject.setValue("createTime", LocalDateTime.now());
        // TODO -更新创建人信息
        // metaObject.setValue("createUser", SharedVariablesCurrent.getCurrent());
        // metaObject.setValue("updateUser", SharedVariablesCurrent.getCurrent());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充【update】");
        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}

